x = int(9999)
z = int(1000)
def isPrime(a):
    if a == 1: return False
    test = True
    k = a - 1
    while k > 1:
        if not a % k:
            test = False
            break
        k -= 1
    return test


n = int(input())
if z <= n and n <= x:
    r = []
    for i in range(len(n)):
        for k in range(i + 1, len(n) + 1):
            a = int(n[i:k])
            if isPrime(a):
                r += [a]
    print(max(r) if r else 0)
else:
    print("0")